package com.hatricks.is.ai;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.util.Objects;

/**
 * @packageName: com.hatricks.is.ai
 * @className: DmxTest
 * @author: yanyuhui y568821795@outlook.com
 * @date: 2025-04-21 22:28
 * @description:
 */
@SuppressWarnings("VulnerableCodeUsages")
public class DmxTest {
    public static void main(String[] args) {
        // DMXAPI 请求地址
        String url = "https://www.dmxapi.com/v1/chat/completions";
        // 构建请求体 JSON
        JSONObject rule = JSONUtil.createObj().set("role", "system").set("content", "You are a helpful assistant.");
        JSONArray array = JSONUtil.createArray();
        JSONObject params = JSONUtil.createObj().set("role", "user").set("content", "生成一张医院的首页大图 给出一个合适的提示词");
        array.add(rule);
        array.add(params);
        // gpt-4-turbo
        // gpt-4o-mini
        // claude-3-5-sonnet-20240620
        // seedream-3.0
        JSONObject payload = JSONUtil.createObj().set("model", "claude-3-5-sonnet-20240620").set("messages", array);
        // 发送 POST 请求
        try (HttpResponse response = HttpRequest.post(url)
                .header("Accept", "application/json")
                .header("Authorization", "sk-vPSCnRhpt4c2hrkcwR7x9zHy4BjJ6J7dlLAtRA6MPM4ySYfn") // 替换为你的 DMXAPI Key
                .header("User-Agent", "DMXAPI/1.0.0 (https://www.dmxapi.com)")
                .header("Content-Type", "application/json")
                .body(Objects.requireNonNull(payload).toString())
                .execute()) {
            System.out.println(response.body());
        }
    }
}
